package com.ruoyi.web.controller.product;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductPrice;
import com.ruoyi.product.service.IProductPriceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品价格Controller
 *
 * @author tanfp
 * @date 2020-12-27
 */
@Controller
@RequestMapping("/product/productPrice")
public class ProductPriceController extends BaseController {
    private String prefix = "product/productPrice";

    @Autowired
    private IProductPriceService productPriceService;

    @RequiresPermissions("product:productPrice:view")
    @GetMapping()
    public String productPrice() {
        return prefix + "/productPrice";
    }

    /**
     * 查询产品价格列表
     */
    @RequiresPermissions("product:productPrice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductPrice productPrice) {
        startPage();
        List<ProductPrice> list = productPriceService.selectProductPriceList(productPrice);
        return getDataTable(list);
    }

    /**
     * 导出产品价格列表
     */
    @RequiresPermissions("product:productPrice:export")
    @Log(title = "产品价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductPrice productPrice) {
        List<ProductPrice> list = productPriceService.selectProductPriceList(productPrice);
        ExcelUtil<ProductPrice> util = new ExcelUtil<ProductPrice>(ProductPrice.class);
        return util.exportExcel(list, "productPrice");
    }

    /**
     * 新增产品价格
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存产品价格
     */
    @RequiresPermissions("product:productPrice:add")
    @Log(title = "产品价格", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductPrice productPrice) {
        return toAjax(productPriceService.insertProductPrice(productPrice));
    }

    /**
     * 修改产品价格
     */
    @GetMapping("/edit/{keyId}")
    public String edit(@PathVariable("keyId") Long keyId, ModelMap mmap) {
        ProductPrice productPrice = productPriceService.selectProductPriceById(keyId);
        mmap.put("productPrice", productPrice);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品价格
     */
    @RequiresPermissions("product:productPrice:edit")
    @Log(title = "产品价格", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductPrice productPrice) {
        return toAjax(productPriceService.updateProductPrice(productPrice));
    }

    /**
     * 删除产品价格
     */
    @RequiresPermissions("product:productPrice:remove")
    @Log(title = "产品价格", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(productPriceService.deleteProductPriceByIds(ids));
    }
}
